﻿using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Web.Security;
using webapp4U;
using webapp4U.BOL;

namespace webapp4U.UI
{
    [ParseChildren(true)]
    public class ddlArticleCategory : DropDownList
    {
        public ddlArticleCategory()
        {
            this.Items.Insert(0, new ListItem(ResourceManager.GetString("PleaseSelect"), "1"));
            List<webapp4U.BOL.ArticleCategory> rootArticleCategory = webapp4U.BOL.ArticleCategory.GetArticleCategoryByParentID(1); // get root level ones

            if (rootArticleCategory.Count > 0)
            {
                foreach (webapp4U.BOL.ArticleCategory c in rootArticleCategory)
                {
                    string strTree = " ";
                    this.CssClass = "dropdownlistParent";
                    ListItem l = new ListItem(strTree + ((Globals.LangVietNam()) ? c.CateName : c.CateName_en), c.CateID.ToString());
                    l.Attributes.Add("style", "font-weight:Bold;");
                    this.Items.Add(l);
                    populateArticleCategoryAdd(c.CateID);
                }
            }
            else
            {
                this.Items.Insert(0, new ListItem("ArticleCategory", "1"));    
            }

        }

        private void populateArticleCategoryAdd(int ParentID)
        {
            string strTree = "     ";
            List<webapp4U.BOL.ArticleCategory> rootArticleCategory = webapp4U.BOL.ArticleCategory.GetArticleCategoryByParentID(ParentID); // get root level ones
            foreach (webapp4U.BOL.ArticleCategory c in rootArticleCategory)
            {
                ListItem l = new ListItem(strTree + ((Globals.LangVietNam()) ? c.CateName : c.CateName_en), c.CateID.ToString());
                //l.Attributes.Add("style", "color:Blue;");
                this.Items.Add(l);
                //this.Items.Add(new ListItem(strTree + c.CateName, c.CateID.ToString()));
                populateArticleCategoryAdd2(c.CateID);
            }
        }

        private void populateArticleCategoryAdd2(int ParentID)
        {
            string strTree = "        ";
            List<webapp4U.BOL.ArticleCategory> rootArticleCategory = webapp4U.BOL.ArticleCategory.GetArticleCategoryByParentID(ParentID); // get root level ones
            foreach (webapp4U.BOL.ArticleCategory c in rootArticleCategory)
            {
                ListItem l = new ListItem(strTree + ((Globals.LangVietNam()) ? c.CateName : c.CateName_en) , c.CateID.ToString());
                //l.Attributes.Add("style", "color:Blue;");
                this.Items.Add(l);
                //this.Items.Add(new ListItem(strTree + c.CateName, c.CateID.ToString()));
                populateArticleCategoryAdd(c.CateID);
            }
        }

    }
}
